package model.roomManagement.Implementation;

import java.io.IOException;


class Timer implements Runnable {
	 static int time=3000;//此毫秒内未收到heart包则说明客户端未成功发生heart包。
	 static int heartTimes=3;//当未收到 heart包超过这个次数，则说明客户断开连接
	 Client client=null;
	
	public Timer(Client client) {
		this.client=client;
	}

	public void run() {
		
	while(true){
		client.lostTime++;
		if(client.lostTime>heartTimes){
			System.out.println("client lost");
				
				try {
					client.socket.close();
				} catch (Exception e) {
				
					e.printStackTrace();
				}
		        break;
		}
			
		 try {
			Thread.sleep(time);
		} catch (InterruptedException e) {
			
			e.printStackTrace();
		}
	
		
	}
	}	

}